﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;

#endregion


namespace ScrumTable.DL.Data.Generic.Cache
{
    /// <summary>
    /// This class wraps a team foundation iteration instance.
    /// </summary>
    public class CacheIteration : CacheElementBase
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        internal const string StartDatePropertyName = "StartDate";
        internal const string EndDatePropertyName = "EndDate";
        private const string IterationPathPropertyName = "IterationPath";

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the associated WIQL iteration path.
        /// </summary>
        public string IterationPath
        {
            get { return Values.TryGetTrackedValue<string>(IterationPathPropertyName); }
            set { TrackValueChange(IterationPathPropertyName, value); }
        }

        /// <summary>
        /// Gets the start date of the iteration.
        /// </summary>
        public DateTime StartDate
        {
            get { return Values.TryGetTrackedValue<DateTime>(StartDatePropertyName); }
            set { TrackValueChange(StartDatePropertyName, value); }
        }

        /// <summary>
        /// Gets the end date of the iteration.
        /// </summary>
        public DateTime EndDate
        {
            get { return Values.TryGetTrackedValue<DateTime>(EndDatePropertyName); }
            set { TrackValueChange(EndDatePropertyName, value); }
        }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new CacheIteration instance. This constructor is used in
        /// the current library only.
        /// </summary>
        internal CacheIteration(
            string uniqueId,
            string backEndId,
            int id,
            double orderIndex,
            string name,
            string iterationPath,
            DateTime startDate,
            DateTime endDate)
            : base(uniqueId, id, name, CacheIdentity.DefaultRevision, orderIndex)
        {
            PreCondition.AssertNotNullOrEmpty(iterationPath, "iterationPath");

            BackEndId = backEndId;

            Values.SetTrackedValue(IterationPathPropertyName, null, iterationPath);
            Values.SetTrackedValue(StartDatePropertyName, default(DateTime), startDate);
            Values.SetTrackedValue(EndDatePropertyName, default(DateTime), endDate);
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new clone instance of the current object.
        /// </summary>
        /// <returns>Returns the created clone instance.</returns>
        protected override CacheElementBase CreateCloneInstance()
        {
            return new CacheIteration(
                UniqueId,
                BackEndId,
                Id,
                OrderIndex,
                Name,
                IterationPath,
                StartDate,
                EndDate);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}